package com.globaldom.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class PersonLocation implements Serializable {

	@NotPersistent
	private static final long serialVersionUID = 1L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String person;
	// Latitude of the city
	@Persistent
	private Float latitude;
	// longitude of the city
	@Persistent
	private Float longitude;
	// Type of city. Home =0,satellites=2, Colonized=3, base=4
	@Persistent
	private Integer locationType = 2;
	@Persistent
	private Date dateCreated;
	@Persistent
	private Integer distance = 0;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getPerson() {
		return person;
	}

	public void setPerson(String person) {
		this.person = person;
	}

	public Float getLatitude() {
		return latitude;
	}

	public void setLatitude(Float latitude) {
		this.latitude = latitude;
	}

	public Float getLongitude() {
		return longitude;
	}

	public void setLongitude(Float longitude) {
		this.longitude = longitude;
	}

	public Integer getLocationType() {
		return locationType;
	}

	public void setLocationType(Integer locationType) {
		this.locationType = locationType;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public Integer getDistance() {
		return distance;
	}

	public void setDistance(Integer distance) {
		this.distance = distance;
	}

public static List<PersonLocation> findCombatantsbyBounds(Long personID, float nlat, float nlon, float slat,
			float slon) {
//		EntityManager em = EMF.get().createEntityManager();
//		String sql = "select o from PersonLocation o where locationType=2 AND (latitude>:slat AND latitude<:nlat) ";
//		Query query = em.createQuery(sql);
//		query.setParameter("nlat", nlat);
//		query.setParameter("slat", slat);
//		query.setMaxResults(500);
//		return query.getResultList();
	return null;
	}

	public static List<PersonLocation> findCombatants(Long personID) {
//		EntityManager em = EMF.get().createEntityManager();
//		String sql = "select o from PersonLocation o where locationType=2 AND person<>:personID ";
//		Query query = em.createQuery(sql);
//		query.setMaxResults(500);
//		return query.getResultList();
		return null;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("Latitude: ").append(getLatitude()).append(", ");
		sb.append("Longitude: ").append(getLongitude()).append(", ");
		sb.append("LocationType: ").append(getLocationType()).append(", ");
		sb.append("DateCreated: ").append(getDateCreated()).append(", ");
		return sb.toString();
	}
}
